var baseUrl = '<?php echo $this->wpSiteUrl;?>';
var baseUrlGallery ='<?php echo $this->wpSiteUrl;?>';
(function($){
	$(document)
	.ready(function(){
		$("#px_structureOptions > ul").tabs();
		
		/**
		 *	Set click event for the options page submit button
		 */
		$('#px_optionsPageSubmit').click(function(){
			var flickr_api_key_val = $('#flickr_api_key').val();
			var flickr_user_id_val = $('#flickr_user_id').val();
			var flickr_photoset_id_val = $('#flickr_photoset_id').val();
			var picasa_user_id_val = $('#picasa_user_id').val();
			var smugmug_api_key_val = $('#smugmug_api_key').val();
			var smugmug_user_id_val = $('#smugmug_user_id').val();
	
			var use_picasa = $('input[name=use_picasa]:checked').val();
			var use_flickr = $('input[name=use_flickr]:checked').val();
			var use_smugmug = $('input[name=use_smugmug]:checked').val();
			var use_album = $('input[name=use_album]:checked').val();
			var use_local = $('input[name=use_local]:checked').val();
			var use_browse = $('input[name=use_browse]:checked').val();
			
			var use_effectSlide = $('input[name=use_effectSlide]:checked').val();
	
			var options_tnimageQuality = $('#options_tnimageQuality').val();
			var options_path = $('#options_path').val();
			var options_delete =  ($('#options_delete').is(':checked')) ? 1 : 0;
			var options_original =  ($('#options_original').is(':checked')) ? 1 : 0;
			var options_MaxWidth = $('#options_MaxWidth').val();
			var options_MaxHeight = $('#options_MaxHeight').val();
			var options_imageQuality = $('#options_imageQuality').val();
			
			var options_thumbailSet = $('input[name=options_thumbailSet]:checked').val();
			var options_dropall = ($('input[name=options_dropall]').is(':checked')) ? 1 : 0;
			
			var options_thumbailW = $('#options_thumbailW').val();
			var options_thumbailH = $('#options_thumbailH').val();
			
			var options_thumbailW2 = $('#options_thumbailW2').val();
			var options_thumbailH2 = $('#options_thumbailH2').val();
			
			
			var use_manager = $('input[name=use_manager]:checked').val();
			var flash_version_multi_upload = $('input[name=flash_version_multi_upload]:checked').val();
			var none_ajax_styles = $('input[name=none_ajax_styles]:checked').val();
	
			
	
			var errors = Array();
	
			if(isEmpty(flickr_api_key_val) && (!isEmpty(flickr_user_id_val) || !isEmpty(flickr_photoset_id_val))){
				//showNoticeMessage('error','You are going to need a Flickr API if you are going to supply a Photoset ID or a User ID');
			};
/*
			if(!isInteger(options_MaxWidth)){
				errors.push('Please Enter numbers only in the max width field');
			};
			
			if(isEmpty(options_MaxWidth)){
				errors.push('Please Enter a numbers in the max width field');
			};
			
			if(!isInteger(options_MaxHeight)){
				errors.push('Please Enter numbers only in the max height field');
			};
			
			if(isEmpty(options_MaxHeight)){
				errors.push('Please Enter a numbers in the max height field');
			};
			
			if(isEmpty(options_path)){
				errors.push('Please Enter an upload path');
			};
			
			if(isEmpty(options_imageQuality)){
				errors.push('Please Enter an upload path');
			};
			
			if(!isInteger(options_imageQuality) || parseInt(options_imageQuality) > 100){
				errors.push('Image quality needs to be a number and less then 100**');
			};
	
	
			if(isEmpty(options_thumbailW)){
				errors.push('Please Enter a thumbnail width size');
			};
			if(!isInteger(options_thumbailW)){
				errors.push('Thumbnail width size must be a number');
			};
			if(isEmpty(options_thumbailH)){
				errors.push('Please Enter a thumbnail height size');
			};
			if(!isInteger(options_thumbailH)){
				errors.push('Thumbnail height size must be a number');
			};
	
			if( typeof options_thumbailSet != "undefined"){
				if(isEmpty(options_thumbailW2)){
					errors.push('Please Enter a thumbnail width size for the second thumbnail');
				};
				if(!isInteger(options_thumbailW2)){
					errors.push('Thumbnail width size must be a number for the second thumbnail');
				};
				if(isEmpty(options_thumbailH2)){
					errors.push('Please Enter a thumbnail height size for the second thumbnail');
				};
				if(!isInteger(options_thumbailH2)){
					errors.push('Thumbnail height size must be a number for the second thumbnail');
				};
			};
			
			if(isEmpty(options_tnimageQuality)){
				errors.push('Please Enter an image quality for the thumbnail');
			};
			
			if(!isInteger(options_tnimageQuality) || parseInt(options_imageQuality) > 100){
				errors.push('Thumbnail image quality needs to be a number and less then 100');
			};
	*/
			
			if(errors.length > 0){
				var i = 0;
				var msg = '';
				for(i = 0; i < errors.length; i++){
					msg += errors[i] +"<br/>";
				};
				showNoticeMessage('error',msg);
				return false;
			};
	
			$.ajax({
				url : baseUrl,
				data : {
					"pxoption" : "optionsSet",
					"flickr_api_key":flickr_api_key_val,
					"flickr_user_id":flickr_user_id_val,
					"flickr_photoset_id":flickr_photoset_id_val,
					"picasa_user_id":picasa_user_id_val,
					"smugmug_api_key":smugmug_api_key_val,
					"smugmug_user_id":smugmug_user_id_val,
					"use_picasa":use_picasa,
					"use_flickr":use_flickr,
					"use_smugmug":use_smugmug,
					"use_album":use_album,
					"use_local":use_local,
					"use_browse":use_browse,
					"options_path":options_path,
					"options_delete":options_delete,
					"options_original":options_original,
					"options_MaxWidth":options_MaxWidth,
					"options_MaxHeight":options_MaxHeight,
					"options_imageQuality":options_imageQuality,
					"options_thumbailSet":options_thumbailSet,
	
					"options_thumbailW":options_thumbailW,
					"options_thumbailH":options_thumbailH,
					
					"options_dropall":options_dropall,
	
					"options_thumbailW2":options_thumbailW2,
					"options_thumbailH2":options_thumbailH2,
					
					"options_tnimageQuality":options_tnimageQuality,
					
					"use_effectSlide":use_effectSlide,
					
					"use_manager":use_manager,
					"flash_version_multi_upload":flash_version_multi_upload,
					"none_ajax_styles":none_ajax_styles
				},
				complete : function(){jQloaderAnimation.hide();},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					var errMsg = "There was an ajax error with a status of " + textStatus + " and thrown error of " + errorThrown;
					showNoticeMessage('error',errMsg);
				},
				beforeSend : function(){jQloaderAnimation.show();},
				success : function(){showNoticeMessage('confirm',"Data Save!");}
			});
			
			
			return false;
		});
		
	});
})(pxjQuery);